Markdown is a way to make fancy documents. Make sure you “Knit” often – after every major change – to mitigate errors. Hashtags are how we make levels of a doc.
This is bold (that’s double asterisks). Or
italics. Or code.
To add a hyperlink, do [link text](url). For example, go to the Sewanee website.
To link to sections of your document, do
[link text](#section-name). For example, go to Markdown. ^keep in mind, no backticks, all
lowercase, _ instead of spaces.
To add more vertical spaces between blocks ot text, use this:
, with lines between them.
Should be more space now.
To include an image – fun! First put an image inside
the folder where you Rmd file is located. Then type
{width="50%"}
RMarkdown is just Markdown with
R woven in.
You can do R stuff in the same line as text. For example 6 will show as 6. (That looks like backtick, lower-case-r, space, code, backtick).
You can also do a full-multi-line CHUNK of R stuff: Create with
```{r} on the first line and ``` on the
last.
3+3
## [1] 6
Settings to control how R chunks appear:
eval=TRUE: which actually runs the code; if
eval=FALSE, it shows the code but doesn’t run it.#this will be shown but not evaluated
3+3
echo=TRUE: which shows the code; if
echo=FALSE, the code can run without being seen.## [1] 8
warnings=FALSE: which will turn off
warning.
fig.cap = "figure caption" adds a figure
caption.
fig.width = 7 example of figure width.
fig.height = 4 example of figure height.
To manually set working directory while building up my RMarkdown file, just fo to Section > Set working directory > Source file locations.
library(readr)
energy <- read_csv("../data/IRENA data.csv", skip=1) #`skip=` to skip the first row at the top that is not actual data
## Rows: 67200 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Country/area, Technology, Data Type, Grid connection, Electricity s...
## dbl (1): Year
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
energy %>% names
## [1] "Country/area" "Technology" "Data Type"
## [4] "Grid connection" "Year" "Electricity statistics"
energy %>% head
## # A tibble: 6 × 6
## `Country/area` Technology `Data Type` `Grid connection` Year
## <chr> <chr> <chr> <chr> <dbl>
## 1 Afghanistan Total renewable Electricity Generation… On-grid 2000
## 2 Afghanistan Total renewable Electricity Generation… On-grid 2001
## 3 Afghanistan Total renewable Electricity Generation… On-grid 2002
## 4 Afghanistan Total renewable Electricity Generation… On-grid 2003
## 5 Afghanistan Total renewable Electricity Generation… On-grid 2004
## 6 Afghanistan Total renewable Electricity Generation… On-grid 2005
## # ℹ 1 more variable: `Electricity statistics` <chr>
energy %>% tail
## # A tibble: 6 × 6
## `Country/area` Technology `Data Type` `Grid connection` Year
## <chr> <chr> <chr> <chr> <dbl>
## 1 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2019
## 2 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2020
## 3 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2021
## 4 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2022
## 5 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2023
## 6 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2024
## # ℹ 1 more variable: `Electricity statistics` <chr>
energy %>% pull(Technology) %>% unique %>% sort
## [1] "Biogas" "Coal and peat" "Geothermal energy"
## [4] "Natural gas" "Nuclear" "Offshore wind energy"
## [7] "Oil" "Onshore wind energy" "Renewable hydropower"
## [10] "Solar photovoltaic" "Total non-renewable" "Total renewable"
Here is a new section where I talk about what I’s doing.
#filter data
fenergy <- energy %>%
filter(`Country/area` == "Germany")
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
p <- ggplot(fenergy,
aes(x = Year,
y = as.numeric(`Electricity statistics`),
fill = Technology))+
geom_area()
ggplotly(p)
## Warning in FUN(X[[i]], ...): NAs introduced by coercion
## Warning: Removed 29 rows containing non-finite outside the scale range
## (`stat_align()`).